var TOKEN_PRODUCT = '6C0C3A58-AD4C-4981-A080-11224BA8A9E7';
var TOKEN_ADD_CART = 'CBE0C82F-3B9D-4BCC-9739-004DB1449374';
var TOKEN_ADD_FAVORITES = '05D85C7B-CF92-42C4-86D5-108DB27A4DB6';
var TOKEN_ADD_CATEGORY = '970284D6-3B61-4495-B303-76B071AD1F35';
var TOKEN_GET_CATEGORY = 'C31F3462-BBA7-4CF2-883D-D658DD2F8DC3';
var TOKEN_GET_COOKIES = '796AD080-F119-48CB-82FC-775A813D5021';
var TOKEN_ORDER_VIEW = '25B05D10-FB5A-42E5-BEAC-05B14DC857A9';
var TOKEN_UPDATE_RANK = 'C55F4A1C-D136-445A-A5D1-5D0500BE6318';
var TOKEN_ADD_CATE = '55947AD2-31F9-4D2F-9EAC-A6C8A6AF07AC';
var TOKEN_UP_CATE = '8D0383BC-6FF7-45D7-A372-20BE4A80E24E';
var TOKEN_DEL_CATE = 'CDD294D5-7A7D-47CF-A114-54CDB10BA03B';
var TOKEN_UP_FACT = '0978F5D7-CD53-40D5-B0F7-A86611ADC0F3';
var TOKEN_DEL_FACT = '319AF369-C3D5-4346-BD18-67593CFFD4BC';
var TOKEN_ADD_FACT = 'BFC94BD1-0FFE-4140-92E5-7A3ABE0D096D';
var TOKEN_UP_ADMIN = 'BFC94BD1-C3D5-40D5-9EAC-05B14DC857A8';
var TOKEN_ADD_ADMIN = '8D0383BC-C3D5-4D2F-F119-775A813D5021';
var TOKEN_DEL_ADMIN = 'C55F4A1C-C3D5-4495-F119-775A813D5021';
var TOKEN_ADD_BANK = '0CED59AE-7121-4D4E-9C96-9DA754CFDF1F';
var TOKEN_DEL_BANK = 'C0EEE356-3ABE-4DD0-9F84-CE4D2CEA9C5B';
var TOKEN_UP_BANK = '26DBB547-76D5-4145-B9F5-1342EA74FCD1';
var TOKEN_ADD_PROD = '1F66149D-33D0-4954-B774-03E79A8F5C21';
var TOKEN_DEL_PROD = '6998E822-BDE6-46E3-AA75-C2B6EF96A23B';
var TOKEN_UP_PROD = 'C502C584-2892-458A-ADF0-AC2C051A6280';
var TOKEN_ADD_MON = '21A443E5-2A7A-4AFA-8AAD-73A60DE39EA5';
var TOKEN_DEL_MON = 'B7E6EA92-1FF7-4762-ABB8-DADD45998BC1';
var TOKEN_UP_MON = 'C0BE3E5E-7FAE-48AA-A3A5-7F09D582BCAF';
var TOKEN_AUDIT_MON = 'C6DA7DA4-A26D-4E52-8000-98A1FE58D1C4';
var TOKEN_ADD_TEMP = '42E08011-D641-4147-AC92-B853D1C91A9C';
var TOKEN_DEL_TEMP = '54D797BA-AC1F-4FF0-BD05-C70CFF94D257';
var TOKEN_UP_TEMP = 'EB3842B5-9865-447A-B19B-F40DCA9F1929';
var TOKEN_VIEW_TEMP = 'C69E5205-9E47-4A9D-A796-A922040E229D';
var TOKEN_ADD_SHIP = '9977682F-2F8E-4590-9A62-E44A7612320B';
var TOKEN_DEL_SHIP = '7D106788-625A-4B0F-8A03-A303333C78F3';
var TOKEN_UP_SHIP = '21FC60EF-FC11-46AA-AFE8-7587118B6A9C';
var TOKEN_ADD_STO = 'A26C6BDE-2326-4B2A-BD18-37C75505CA0A';
var TOKEN_DEL_STO = 'EAA3E0CD-9E49-4950-932E-28F2B74D56BC';
var TOKEN_UP_STO = 'F7796B44-19E9-4849-A8E1-D8095DD6CD31';
var TOKEN_SELL_STO = '244B50D3-AD42-45F8-BA02-379509926906';
var TOKEN_UPSELL_SELL ='78554877-7167-4AE3-90F0-4B1ABCE33C81';
var TOKEN_LOAD_IMPORTANT = 'F530ED25-145D-4BFC-A8B9-4AA938865C7F';
var TOKEN_LOAD_CATEGORY = '99BE74A3-E80E-4E89-AFCD-1ED06034EE9B';
var TOKEN_LOAD_FACTORY = 'AC45FDCF-163A-4204-A34F-DEAE56CA736C';
var TOKEN_LOAD_CATEGORY_BACK = '6BBEB9B0-6159-4571-BB39-69A678188B4E';
var TOKEN_LOAD_IMAGES = '604E335B-5ACF-4F4E-98D1-5C9E4D8DFB6C';
var TOKEN_ADD_HNEWS = '00970A19-7924-450B-BE79-C4D8CE141EA5';
var TOKEN_DEL_HNEWS = '531BDC5B-D11D-49F6-8CA6-AB6215DBF898';
var TOKEN_UP_HNEWS = 'AA07E660-837E-43A5-AB29-B3635EF49E65';

var TOKEN_ADD_HSELL = '5C6E3724-046E-41F8-A9EA-EF9DFE8FA851';
var TOKEN_DEL_HSELL = 'EFB4F45A-982A-4CB6-B884-4CD49FC4AA55';
var TOKEN_UP_HSELL = 'D985C6EB-2A42-4C90-B814-A595E36F8334';

var AJAX_GLOBAL_TOKEN_CWS_JP_ZIP = '3D10D249-DFBA-48F0-A982-ACBD608E7834';
var AJAX_GLOBAL_CWS_JP_ZIP = '<{$ROOTPATH}>/ws/jp/zip/';

var ajax_callback_page = '/cs2/include/tools/Xurrency.php';

// 默认AJAX
$.ajaxSetup({
	type: 'POST',
	global: true,
	timeout:3000,
	dataType:'json'
});


// 窗口显示模块
var blockDesign = {
	recall:'default.php',
	defualt:function(msg,w,recall){
		$.blockUI({
            message: msg, 
            fadeIn: 700,
            fadeOut: 700,
            showOverlay: false, 
            centerY: false, 
            css: { 
                width: w, 
                top: '10px', 
                left: '', 
                right: '10px', 
                border: '1px solid #000066', 
                padding: '5px', 
                backgroundColor: '#ee9900', 
                color: '#000',
                '-webkit-border-radius': '5px', 
                '-moz-border-radius': '5px', 
                opacity: .6
            },
            timeout: 3000,
            onBlock: function(){
				location.href=blockDesign.recall;
            }
        }); 
	},
	showinfo:function(msg,w,recall){
		$.blockUI({
            message: msg, 
            fadeIn: 700,
            fadeOut: 700,
            showOverlay: false, 
            centerY: false, 
            css: { 
                width: w, 
                top: '10px', 
                left: '', 
                right: '10px', 
                border: '1px solid #000066', 
                padding: '5px', 
                backgroundColor: '#ee9900', 
                color: '#000',
                '-webkit-border-radius': '5px', 
                '-moz-border-radius': '5px', 
                opacity: .6
            },
            timeout: 3000
        }); 
	},
	form:function(msg,w,t,l){
		$.blockUI(
			{ 
				message: msg,
				fadeIn: 700,
	            fadeOut: 700,
	            showOverlay: true, 
	            centerY: false, 
	            css: { 
	                width: w, 
	                top: t, 
	                left: l, 
	                border: '1px solid #000', 
	                padding: '5px', 
	                backgroundColor: '#000033', 
	                '-webkit-border-radius': '5px', 
	                '-moz-border-radius': '5px', 
	                opacity:1, 
	                color: '#fff' ,
	                cursor: 'default'
	            }
			});
	},
	message:function(msg,w){
		$.blockUI({ 
			message: msg,
			css: { 
                width: w, 
                border: '1px solid #000', 
                padding: '5px', 
                backgroundColor: '#000033', 
                '-webkit-border-radius': '5px', 
                '-moz-border-radius': '5px', 
                opacity:1, 
                color: '#fff' ,
                cursor: 'default'
            }
		});
	}
};


/* 一个Ie下文本框聚焦时，光标不能自动定位到文本末尾的问题，在此小记下解决方法：
 * 公用方法
 * utilityHandle.setFocus()  设置文本焦点定位方  (参数 objFocusEven:将设置聚焦的控件对象;values:焦点定位位置）
 * */
var utilityHandle = {
	setFocus:function(objFocusEven,values){
		objFocusEven.focus(); // 默认使用focus方法聚焦 
		// 判断是否为Ie浏览器
		if ($.browser.msie) {
			var txt = objFocusEven[0].createTextRange(); // 将传入的控件对象转换为Dom对象，并创建一个TextRange对象
			txt.moveStart('character', values);   // 设置光标显示的位置
			txt.collapse(true);
			txt.select(); 
		}
	},
	trim:function(str){  
	    str = str.replace(/^(\s|\u00A0)+/,'');  
	    for(var i=str.length-1; i>=0; i--){  
	        if(/\S/.test(str.charAt(i))){  
	            str = str.substring(0, i+1);  
	            break;  
	        }  
	    }  
	    return str;  
	},
	trimString:function(str)
	{
		 var i,j;
		 if(str == "") return "";
		 for(i=0;i<str.length;i++)
		 if(str.charAt(i) != ' ') break;
		 if(i >= str.length) return "";
		 for(j=str.length-1;j>=0;j--)
		 if(str.charAt(j) != ' ') break;
		 return str.substring(i,j+1);
	},
	cTrim:function (sInputString,iType)
	{
		var sTmpStr = ' '
		var i = -1
		if(iType == 0 || iType == 1)
		{
		while(sTmpStr == ' ')
		{
		++i
		sTmpStr = sInputString.substr(i,1)
		}
		sInputString = sInputString.substring(i)
		}
		if(iType == 0 || iType == 2)
		{
		sTmpStr = ' '
		i = sInputString.length
		while(sTmpStr == ' ')
		{
		--i
		sTmpStr = sInputString.substr(i,1)
		}
		sInputString = sInputString.substring(0,i+1)
		}
		return sInputString
	},
	outputMoney:function (number) { 
		number = number.replace(/\,/g,""); 
		if (number=="") 
			return ""; 
		if(number<0) 
			return '-'+this.outputDollars(Math.floor(Math.abs(number)-0) + '');// + this.outputCents(Math.abs(number) - 0); 
		else 
			return this.outputDollars(Math.floor(number-0) + '');// + this.outputCents(number - 0); 
	},
	
	outputDollars:function (number) 
	{ 
	  if (number.length<= 3) 
	  return (number == '' ? '0' : number); 
	  else 
	  { 
	    var mod = number.length%3; 
	    var output = (mod == 0 ? '' : (number.substring(0,mod))); 
	    for (i=0 ; i< Math.floor(number.length/3) ; i++) 
	    { 
	      if ((mod ==0) && (i ==0)) 
	      output+= number.substring(mod+3*i,mod+3*i+3); 
	      else 
	      output+= ',' + number.substring(mod+3*i,mod+3*i+3); 
	    } 
	    return (output); 
	  } 
	} ,
	outputCents:function (amount) 
	{ 
	  amount = Math.round( ( (amount) - Math.floor(amount) ) *100); 
	  return (amount<10 ? '.0' + amount : '.' + amount); 
	},
	outputRate:function(amount){
		var sl = amount.split('.');
		if(sl.length > 1)
			return (sl[0]+"."+sl[1].substring(0,3));
		else
			return sl[0];
	},
	select_date:function(me,yb){
		year = 2010;
		if(yb == undefined)
			year = 2010;
		$('.'+ jSelectDate.yearClass).remove();
		$('.'+ jSelectDate.monthClass).remove();
		$('.'+ jSelectDate.dayClass).remove();
		$(me).jSelectDate({
			css:"date",
			yearBeign: year,
			kannjiShow:true,
		});
	},
	copyToClipboard:function(txt) {   
      if(window.clipboardData) {   
              window.clipboardData.clearData();   
              window.clipboardData.setData("Text", txt);
            alert("コピー完了しました。");   
      } else if(navigator.userAgent.indexOf("Opera") != -1) {   
           window.location = txt;   
      } else if (window.netscape) {   
           try {   
                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");   
           } catch (e) {   
                alert("如果您正在使用FireFox！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");   
           }   
           var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);   
           if (!clip)   
                return;   
           var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);   
           if (!trans)   
                return;   
           trans.addDataFlavor('text/unicode');   
           var str = new Object();   
           var len = new Object();   
           var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);   
           var copytext = txt;   
           str.data = copytext;   
           trans.setTransferData("text/unicode",str,copytext.length*2);   
           var clipid = Components.interfaces.nsIClipboard;   
           if (!clip)   
                return false;   
           clip.setData(trans,null,clipid.kGlobalClipboard);   
           alert("コピー完了しました。")   
      }
	},
	// 日文半角设置
	toHankaku:function (c){
		var t = '';
		for (i=0;i<c.value.length;i++) {
			s=c.value.charCodeAt(i);
			if ((0xff0f<s) && (s<0xff1a)) {
				t+=String.fromCharCode(s-0xfee0);
			} else {
				t+=String.fromCharCode(s);
			}
		}
		t = t.replace(/,/g,''); // 去逗号 半角
		t = t.replace(/，/g,''); // 去逗号 全角
		c.value = t
	},
};

// 全局警示标签变量
var verif_box = '#verif_box';

var validation = {
	// 只能英文
	onlyEng : function(){
		if(!(event.keyCode>=65&&event.keyCode<=90)){
			event.returnvalue=false;
		}
	},
	// 只能数字
	onlyNumber :function(){
		// 考虑小键盘上的数字键
		if(!((event.keyCode>=48&&event.keyCode<=57)||(event.keyCode>=96&&event.keyCode<=105))){
			event.returnvalue=false;
		}
	},
	// 电子邮件
	isEmail : function(strEmail){
		if(strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
			return true;
		} else {
			//alert("oh ,no");
			return false;
		}
	},
	// 密码相同
	checkPasswd : function (pwd,pwd1){
		if($(pwd).val() != $(pwd1).val()){
			$(pwd).val("");
			$(pwd1).val("");
			return false;
		} else {
			return true;
		}
	},
	// 密码不能为空
	checkFormBlank : function (test){  
		if ($(test).val().length == 0) {  
			$(test).focus();
			return false;
		}
		return true;
	},
	// 是数字
	isNumber : function (String){  
		var Letters = "1234567890-"; //可以自己增加可输入值
		var i;
		var c;
		var res = true
		if(String.charAt( 0 )=='-')
			res = false;
		if( String.charAt( String.length - 1 ) == '-' )
			res = false;
		for( i = 0; i < String.length; i ++ ){
			c = String.charAt( i );
			if (Letters.indexOf( c ) < 0)
			res = false;
		}
		return res;
	},
	// 是金额
	isMoney : function(String){  
		var Letters = "1234567890."; //可以自己增加可输入值
		var i;
		var c;
		var res = true
		if(String.charAt( 0 )=='.')
			res = false;
		if( String.charAt( String.length - 1 ) == '.' )
			res = false;
		for( i = 0; i < String.length; i ++ ){
			c = String.charAt( i );
			if (Letters.indexOf( c ) < 0)
			res = false;
		}
		return res;
	},
	// 是整数
	isInteger : function(String){  
		var Letters = "1234567890"; //可以自己增加可输入值
		var i;
		var c;
		var res = true
		if(String.charAt( 0 )=='0')
			res = false;
		for( i = 0; i < String.length; i ++ ){
			c = String.charAt( i );
			if (Letters.indexOf( c ) < 0)
			res = false;
		}
		return res;
	},
	// 是英数加符合-_.
	isEngNumber : function(String){
		var Letters = "0123456789-_.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; //可以自己增加可输入值
		var i;
		var c;
		var res = true
		if(String.charAt( 0 )=='-')
			res = false;
		if(String.charAt( 0 )=='.')
			res = false;
		if(String.charAt( 0 )=='_')
			res = false;
		if( String.charAt( String.length - 1 ) == '-' )
			res = false;
		if( String.charAt( String.length - 1 ) == '.' )
			res = false;
		if( String.charAt( String.length - 1 ) == '-' )
			res = false;
		for( i = 0; i < String.length; i ++ ){
			c = String.charAt( i );
			if (Letters.indexOf( c ) < 0)
				res = false;
		}
		return res;
	},
	// content = "您的电话号码规格不符合要求！";
	checkTel : function(test,content){ 
		if(! isNumber($(test).val())){  
			alert(content);
			$(test).focus();
			return false;
		}
		return true;
	}
};

String.prototype.getQuery = function(name) {  
　　var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");  
　　var r = this.substr(this.indexOf("\?")+1).match(reg);  
　　if (r!=null) return unescape(r[2]); return null;  
}  

String.prototype.setQuery = function(name,pvalue){
    var reg = new RegExp("(\\?|&)"+ name +"=([^&]*)(&|$)","gi");
    var m = this.match(reg);
    if(m == null){
    	if(this.indexOf("?") < 0){
    		return this + '?'+ name + '=' + pvalue;
    	}else{
    		return this + '&'+ name + '=' + pvalue;
    	}
    	
    }else{
	    var t=this.match(reg)[0];
	    var retxt=t.substring(0,t.indexOf("=")+1)+pvalue;
	    if(t.charAt(t.length-1)=='&') retxt+="&";
	    return this.replace(reg,retxt);
    }
    
}


jQuery(function($){
	//这行是 Opera 的补丁, 少了它 Opera 是直接用跳的而且画面闪烁 by willin
	$body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
	//$('select').sSelect();
	for(var i = 0 ; i< $('.typeMoney').length; i++){
		$('.typeMoney')[i].innerText = utilityHandle.outputMoney($('.typeMoney')[i].innerText);
	}
	for(var i = 0 ; i< $('.typeRate').length; i++){
		$('.typeRate')[i].innerText = utilityHandle.outputRate($('.typeRate')[i].innerText);
	}
	$('.typeLink').bind("mouseover", function(){
		$(this).attr('class','typeLink_on');
	});
	$('.typeLink').bind("mouseout", function(){
		$(this).attr('class','typeLink');
	});
	
	// 汇率显示器
	 $('#currency').jCurrency();
});



function scrollTo(id){
	$body.animate({scrollTop: $(id).offset().top}, 1000);
}